//
//  HttpManager.m
//  LCExpress
//
//  Created by mac1 on 15/10/13.
//  Copyright © 2015年 D0. All rights reserved.
//

#import "HttpManager.h"
#import "AFNetworking.h"

@implementation HttpManager

-(HttpManager*)initWithSecurity
{
    self = [super self];
    
    if(self)
    {
        // 网络请求管理者
        //AFHTTPRequestOperationManager *manager = [ AFHTTPRequestOperationManager manager];
        
        self.responseSerializer = [AFHTTPResponseSerializer serializer];
        
        //安全验证对象
        AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
        
        securityPolicy.allowInvalidCertificates =YES;
        
        securityPolicy.validatesDomainName =NO;
        
        [self setSecurityPolicy:securityPolicy];
    }

    return self;
}


-( void )getWithUrl:(NSString*)url withDataBlock:(blockData)dataBlock
{

    [self GET:url  parameters:nil
        success :^( AFHTTPRequestOperation *operation, id responseObject)
     {
        //将结果抛给数据中心
        if(dataBlock)
             dataBlock(responseObject);
     }
        failure :^( AFHTTPRequestOperation *operation, NSError *error)
     {
         NSLog ( @"请求失败:%@" ,[error description ]);
     }];
}


-(void)postWithUrl:(NSString*)url withParameters:(NSDictionary*)dic withDataBlock:(blockData)dataBlock
{
    [self POST :url parameters : dic
          success :^( AFHTTPRequestOperation *operation, id responseObject)
     {
         //将结果抛给数据中心
         if(dataBlock)
             dataBlock(responseObject);
     }
          failure :^( AFHTTPRequestOperation *operation, NSError *error)
     {
         NSLog ( @"请求失败:%@" ,[error description ]);
     }];
}


@end
